<script>
    /**
     * 管理员编辑
     * @Author Mumu xinglinhe@qq.com
     * @Date 2022/09/13
     */
    export default{
        components:{
    
        },
        props:{
    
        },
        data(){
            return {
                visible:false,
                data:{},
                loading:false,
            }
        },
        created(){},
        mounted(){},
        methods:{
            send(){
                this.$refs.forms.validate().then(async ()=>{
                    console.log('验证通过');
                    this.loading=true;
                    let rs = await this.muajax.adminrolesave({
                        ...this.data,
                    });
                    this.loading=false;
                    if(rs.code==200){
                        this.$message.success(rs.msg);
                        this.visible=false;
                        this.$emit("update_list");
                    }
                }).catch(err=>{
                    console.log('验证不通过');
                    // this.$errorFocus(err);
                })
            },
            async datainit(){
                let rs = await this.muajax.adminGet({ id : this.param.id});
                if(rs.code==200){
                    this.data=rs.data;
                }
            },//初始化本页数据
            show(show,param){
                this.visible=show;
                if(param) {
                    if(show){
                        this.param=param;
                        if(!!this.param?.id)
                            this.datainit();
                    }
                } else {
                    this.data=[{}];
                }
            },
    
        },
        computed:{},
        watch:{},
        filters:{},
    }
    </script>
    <template>
        <a-modal
            v-model:visible="visible"
            width="500px"
            title="编辑角色"
            :maskClosable="false"
            @ok="send"
            cancelText="取消"
            okText="提交"
            :confirmLoading="loading"
        >
            <a-form
            ref="forms"
            :model="data"
            >
                <a-form-item
                    label="姓名"
                    :labelCol="{span: 7}"
                    name="user_name"
                    :rules="[{required:true,message:'请输入姓名'}]"
                >
                    <a-input
                        placeholder="请输入"
                        v-model:value="data.user_name"
                    />
                </a-form-item>

                <a-form-item
                    label="角色"
                    :labelCol="{span: 7}"
                    name="role_id"
                    :rules="[{required:true,message:'请选择角色'}]"
                >
                    <a-select
                        v-model:value="data.role_id"
                        label-in-value
                        style="width: 120px"
                        placeholder="请选择"
                        :options="data.role_list"
                        @change="handleChange"
                    >
                    </a-select>
                </a-form-item>
            </a-form>
        </a-modal>
    </template>
    <style lang="less" scoped>
    
    </style>